﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.Diagnostics;
using FluentScheduler;
using YiYiTong.Rocket.Helper;
using System.ServiceProcess;
using YiYiTong.Rocket.Helper.Redis;
using YiYiTong.Rocket.Business;
using System.Threading;

namespace YiYiTong.Rocket.ProcessConsole
{
    static class Program
    {
        static void Main(string[] args)
        {
            //从APP.CONFIG中读取日志的信息(不加此处无法产生日志)
            log4net.Config.XmlConfigurator.Configure();

            Thread thread = new Thread(new ThreadStart(SessionBiz.Instance.Subscription));
            thread.Start();

            

            ///通过配置文件配置是已服务启动还是以控制台程序启动
            if (ConfigHelper.AppSetting<int>("ServerRunType", 2) == 2)
                ConsleStart(args);
            else
                ServiceStart(args);
        }


        static void ServiceStart(string[] args)
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[]
            {
                new ProcessCenter()
            };
            ServiceBase.Run(ServicesToRun);
        }


        static void ConsleStart(string[] args)
        {
            //执行job
            JobManager.Initialize(new ProcessConsoleReg());
            Console.WriteLine("输入exit退出");
            while (Console.ReadLine() != "exit")
            {
                //空循环，保证只有输入Exit才退出
            }
            Console.WriteLine("按任意键退出");
            Console.ReadKey();
            JobManager.Stop();
            Console.WriteLine("系统退出。");
        }
    }
}
